//
//  UIBezierPath+Bezier.m
//  YunHaiManage
//
//  Created by zhangbolin on 2021/12/17.
//

#import "UIBezierPath+Bezier.h"

@implementation UIBezierPath (Bezier)

+ (instancetype)qjn_bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius {
    UIBezierPath *path = [UIBezierPath bezierPath];
    CGFloat x = rect.origin.x;
    CGFloat y = rect.origin.y;
    CGFloat width   = rect.size.width;
    CGFloat height  = rect.size.height;
    CGFloat radius = (cornerRadius > height * 0.5) ? height * 0.5 : cornerRadius;
    [path moveToPoint:CGPointMake(x + radius, y)];
    [path addLineToPoint:CGPointMake(x + width - radius, y)];
    [path addArcWithCenter:CGPointMake(x + width - radius, y + radius) radius:radius startAngle:-M_PI_2 endAngle:0 clockwise:YES];
    [path addLineToPoint:CGPointMake(x + width, y + height - radius)];
    [path addArcWithCenter:CGPointMake(x + width - radius, y + height- radius) radius:radius startAngle:0 endAngle:M_PI_2 clockwise:YES];
    [path addLineToPoint:CGPointMake(x +radius, y + height)];
    [path addArcWithCenter:CGPointMake(x +radius, y + height - radius) radius:radius startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
    [path addLineToPoint:CGPointMake(x, y + radius)];
    [path addArcWithCenter:CGPointMake(x +radius, y + radius) radius:radius startAngle:M_PI endAngle:-M_PI_2 clockwise:YES];
    return path;
}

@end
